#!usr/bin/env python3

#一些for循环的技巧
import os,zlib

''' 想要同时迭代两个序列，用zip,迭代的次数是较短序列的长度  '''
arr1 = ["cx", "wb"]
arr2 = ["山东", "河北", "江西"]
for person, hometown in zip(arr1, arr2):
    print("{0}的家乡是{1}".format(person, hometown), end=",")
    
#zlib压缩和解压

def getContent(filename,mo="r+",**kwargs):    
    print("filename",filename)
    with open(filename,mo,**kwargs) as f:
        data=f.read()
    return data
def compress(data):
    data = data.encode("utf-8")    
    data = zlib.compress(data)    
    return data
    
def writeFile(byteData,url,mo="wb"):
    with open(url,mo) as f:#以二进制方式写入 
        f.write(byteData) 
        
def decompress(byteData):
    data = zlib.decompress(byteData)
    data = data.decode()
    return data
    
ROOT_URL = os.path.split(__file__)[0]
filename = os.path.join(ROOT_URL,"03001.png")
filename = os.path.join(ROOT_URL,"5.xml")
data = getContent(filename,"r+",encoding='utf-8')
print(data)
data = compress(data)
print("压缩后....")
print(data)
save_url =  os.path.join(ROOT_URL,"iofile")
save_url =  os.path.join(save_url,"data.lib")
writeFile(data,save_url)
print("压缩文件的内容")
data = getContent(save_url,'rb') #以二进制方式读取
print(type(data))
data = decompress(data)
print("结压后..")
print(data)

from datetime import datetime
print(datetime.utcnow())
print(type(datetime.now())) 
print(datetime.now())
     

class MyObj(object):
    def __init__(self,id):
        self.id = id
        
        
obj2Id = {}

obj = MyObj(2)

obj2Id[obj] = obj.id
print(obj2Id)
import struct
packByte = struct.pack('>I', 10240099)
print(packByte,struct.unpack('I',packByte))


 
    
